//
//  UITextField+Msg.m
//  CarService
//
//  Created by sixarm on 2018/4/18.
//  Copyright © 2018年 sixarm. All rights reserved.
//

#import "UITextField+Msg.h"
#import <objc/runtime.h>

NSString * const JSTextFieldDidDeleteBackwardNotification = @"textfield_did_notification";

@implementation UITextField (Msg)
+ (void)load {
    Method method1 = class_getInstanceMethod([self class], NSSelectorFromString(@"deleteBackward"));
    Method method2 = class_getInstanceMethod([self class], @selector(wj_deleteBackward));
    method_exchangeImplementations(method1, method2);
}

- (void)wj_deleteBackward {
    [self wj_deleteBackward];
    
    if ([self.delegate respondsToSelector:@selector(textFieldDidDeleteBackward:)])
    {
        id <JSTextFieldDelegate> delegate  = (id<JSTextFieldDelegate>)self.delegate;
        [delegate textFieldDidDeleteBackward:self];
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:JSTextFieldDidDeleteBackwardNotification object:self];
}

/** 设置 textfield 前端缩进距离 **/
+ (void) wj_setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth
{
    CGRect frame = textField.frame;
    frame.size.width = leftWidth;
    UIView *leftview = [[UIView alloc] initWithFrame:frame];
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = leftview;
}


@end
